package com.duzhuo.springsecurity.handler;

import com.duzhuo.springsecurity.entity.PhoneCodeAuthentication;
import lombok.Data;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

public class PhoneCodeAuthenticationProvider implements AuthenticationProvider {
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        String name = authentication.getName();
        Object credentials = authentication.getCredentials();
       //todo 认证
        if (name.equals("13048433201") && credentials.equals("123")){
            return authentication;
        }
        return null;
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return (PhoneCodeAuthentication.class
                .isAssignableFrom(authentication));
    }
}
